package com.chanzany.mediator;

import java.util.NoSuchElementException;

/**
 * @Author ChanZany
 * @Date 2021/10/19 10:22
 * @Version 1.0
 * 具体的中介者角色类
 */
public class ConcreteMediator extends Mediator {

    @Override
    public void contact(String message, Person person) {
        if (person instanceof HouseOwner){  //如果是房主，则租房者获得信息
            for (Person p: colleagues){
                if (p instanceof Tenant){
                    ((Tenant) p).getMessage(message);
                }
            }
        }else if (person instanceof Tenant){ //反则是房主获得信息
            for (Person p: colleagues){
                if (p instanceof HouseOwner){
                    ((HouseOwner) p).getMessage(message);
                }
            }
        }else {
            throw new NoSuchElementException("暂时只有两个同事角色");
        }
    }
}
